package com.chenchao.javacommonclass;

/**
 * @encoding : UTF-8
 * @Time : 2020/11/11 19:14
 * @Author : Chen Chao
 * @File : javaSE.com.chenchao.commonclass.StringTest3.java
 * @Software : IntelliJ IDEA
 * @since : 1.8
 * StringBuilder
 */
public class StringTest3 {
    //默认创建一个16空间大小的StringBuilder
    //超出会自动扩容 现在值*2+2
    //value = new char[capacity];本质还是个数组
    public static void main(String[] args) {
        StringBuilder s1=new StringBuilder();
        StringBuilder s2=new StringBuilder(16);
        //获取容量
        System.out.println(s2.capacity());
        //添加,可以添加任意类型,返回值为this
        s1.append(1).append("afdvarevdav");
        s1.append(1).append("afdvare");

        System.out.println(s1);
        //删除指定位置的字符
        s1.deleteCharAt(1);
        System.out.println(s1);
        System.out.println(s1.capacity());

        //可变转不可变
        String s=s1.toString();
        //不可变转可变(构造器)
        StringBuilder s3=new StringBuilder(s);

        //字符串反转
        System.out.println(s3.reverse());

    }
}
